package com.cn.yugan.Utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by Rover on 2016/10/7 .
 * Email 357319517@qq.com
 */
public class StreamUtils {
    /**
     * 把IO流转成String
     * 返回String，如果报错就返回null;
     * @param is 
     * @return 
     */
    public static String readStream(InputStream is)  {

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = is.read(buffer)) != -1) {
                baos.write(buffer, 0, len);
            }
            is.close();
            return baos.toString();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
